package com.sxygsj.baselibrary.fragment

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.qmuiteam.qmui.util.QMUIDisplayHelper
import com.qmuiteam.qmui.util.QMUIStatusBarHelper

/**
 * Author: sxygsj
 * Date: 2021/2/26 15:35
 * Description:
 * History:
 */
abstract class BaseFragment:Fragment() {
    protected lateinit var mActivity:FragmentActivity
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        onBeforeCreatView(savedInstanceState)
        return inflater.inflate(setLayoutResouceId(),container,false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initData(arguments)
    }

    override fun onAttach(context: Context) {
        super.onAttach(context)
        activity?.let {
            mActivity=it
        }
    }
    abstract fun onBeforeCreatView(savedInstanceState: Bundle?)
    abstract fun setLayoutResouceId():Int
    abstract fun initData(arguments:Bundle?)

    /**
     * 沉浸式状态栏
     */
    protected fun immerseStatusBar(){
        QMUIStatusBarHelper.translucent(mActivity)
    }

    /**
     * 设置状态栏黑色字体图标
     */
    protected fun setStatusBarLightMode(){
        QMUIStatusBarHelper.setStatusBarLightMode(mActivity)
    }

    /**
     * 设置状态栏白色字体图标
     */
    protected fun setStatusBarDarkMode(){
        QMUIStatusBarHelper.setStatusBarDarkMode(mActivity)
    }
    /**
     * 获取状态栏高度
     */
    protected fun getStatusBarHeight():Int{
        return QMUIStatusBarHelper.getStatusbarHeight(mActivity)
    }
    /**
     * 获取虚拟导航栏的高度，无返回0
     */
    private fun getNavMenuHeight():Int{
        return QMUIDisplayHelper.getNavMenuHeight(mActivity)
    }

}